CM-62578: Expose Cycode API v4 through CLI commands#435
Conversation
There was a problem hiding this comment.
I think we should put all the commands under an api namespace so like cycode api violations right now its really cluttering up the main commands and means we can have naming collisions. This is similar to what github is doing for their CLI. Also if we do this it means when we run unrelated tasks we wont have pull the swagger file, we should try and do this as when CLI is run in CI/CD it will never be hitting cache.
Here is an example of where you get some annoying logging in a command due to the call for openAPI being made in the background.
poetry run cycode status
[04/13/26 10:34:02] WARNING [API Command] Could not load OpenAPI spec: Cycode credentials not found. Run `cycode auth` first, or set CYCODE_CLIENT_ID and CYCODE_CLIENT_SECRET environment variables. api_command.py:128
Program: cycode
Version: 0.0.0
Os: Darwin
Arch: arm64
Python version: 3.13.7
Installation id: xxxx
App url: https://app.cycode.com
Api url: https://api.cycode.com
Is authenticated: False
User id: None
Tenant id: None
Supported modules:
Secret scanning: False
Sca scanning: False
Iac scanning: False
Sast scanning: False
Ai large language model: False
....
Lastly we will need to add documentation to the Readme for these new commands. Having it under the api namespace will make this a bit easier I think in explaining generally what it does since its dynamic
|
@gotbadger Great feedback, thank you — all three points are valid. You're right about the concrete issues:
On namespacing, going with I looked at how other CLIs handle this. Since we can't easily bundle the spec (it's tenant-aware and changes more frequently than CLI releases), namespacing is the right call. Plan:
|
gotbadger
left a comment
There was a problem hiding this comment.
Think we are mostly good structure wise here now, couple of things I spotted.
Add a new `cycode platform <resource> <action>` command namespace with subcommands generated dynamically from the Cycode API v4 OpenAPI spec. Key design decisions: - Commands live under a `platform` namespace to avoid collisions with curated commands (scan, auth, status) and to signal "platform surface" rather than "raw API escape hatch" - Spec is lazy-loaded: only fetched when the user enters `cycode platform`, so unrelated commands never trigger a network call or auth check - Cached at ~/.cycode/openapi-spec.json for 24h with atomic writes - Path-based command naming derived from URL structure (not summary parsing) - Uses the CLI's standard auth client (CycodeTokenBasedClient) - All commands marked [BETA] - URL-encodes path params to prevent path traversal New files: - cycode/cli/apps/api/__init__.py — PlatformGroup (lazy Click group) - cycode/cli/apps/api/api_command.py — OpenAPI-to-Click translator - cycode/cli/apps/api/openapi_spec.py — spec fetch, cache, parse - tests/cli/apps/api/ — 25 unit tests Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2b5d1f0 to
a616a1f
Compare
Summary
app.cycode.comand cached locally for 24h[EXPERIMENT]Examples
Projects
cycode projects list --page-size 10 --query "Frontend" cycode projects view 29303 cycode projects collisions --project-id 123 cycode projects collisions-count --project-id 123 cycode projects assets --project-id 123Violations
Workflows
Members
Compliance
Audit logs
Scans & statistics
Other resources
Discovery
Architecture
app.cycode.com/v4/api-docs/cycode-api-swagger.jsonwith a 3s timeoutlistfor collections,viewfor single resources/violations/count→countCycodeTokenBasedClient(same as all other CLI commands)Test plan
cycode projects list --page-size 2returns project datacycode violations list --severity Critical --status Openreturns filtered violationscycode projects view <ID>returns single project (path param)cycode violations count --severity Highreturns countcycode workflows listreturns workflowscycode members rolesreturns rolescycode --helpshows API command groups with [EXPERIMENT] labelJira: CM-62578
🤖 Generated with Claude Code